import Vue from 'vue'
import VueRouter from 'vue-router'

// Vue加载插件的语法
Vue.use(VueRouter)

// 再导出VueRouter实例，这里格式是：VueRouter实例的参数是一个对象
export default new VueRouter({
  // routes(路由):即url输入对应的路径,加载显示对应的组件
  //
  routes: [
    {
      path: '/',
      name: 'home', // 若这里取了name,则对应导入的component组件中也要定义相同的name: 'home'
      component: () => import('./../views/home.vue'),
      redirect: '/index', // 默认输入xxx:8080 跳转到 xxx:8080/index中
      children: [
        // 首页
        { path: '/index', name: 'index', component: () => import('./../views/index.vue') },
        { path: '/search', name: 'index', component: () => import('./../views/search.vue') },
        { path: '/category/:id', name: 'index', component: () => import('./../views/category.vue') },


        // 现货列表
        { path: '/xianhuo', name: 'xianhuo', component: () => import('./../views/xianhuo.vue') },
        // 期货列表
        { path: '/qihuo', name: 'qihuo', component: () => import('./../views/qihuo.vue') },
        //  详情
        { path: '/detail/:id', name: 'detail', component: () => import('./../views/detail.vue') }, 
      ]
    },
    { path: '/login', name: 'login', component: () => import('./../views/login.vue') },
    { path: '/cart', name: 'cart', component: () => import('./../views/cart.vue') },
    // 会员中心(个人资料、收货地址、收藏、订单)
    {
      path: '/user',
      name: 'user',
      component: () => import('./../views/user.vue'),
      children: [
        { path: '/userProfile', name: 'profile', component: () => import('./../views/userProfile.vue') },
        { path: '/userAddress', name: 'address', component: () => import('./../views/userAddress.vue') },
        { path: '/userCollect', name: 'collect', component: () => import('./../views/userCollect.vue') },
        { path: '/userOrder', name: 'alipay', component: () => import('./../views/userOrder.vue') }
      ]
    },
    {
      path: '/order',
      name: 'order',
      component: () => import('./../views/order.vue'),
      children: [
        { path: '/order/list', name: 'order-list', component: () => import('./../views/orderList.vue') },
        { path: '/order/confirm', name: 'order-confirm', component: () => import('./../views/orderConfirm.vue') },
        { path: '/order/pay', name: 'order-pay', component: () => import('./../views/orderPay.vue') },
        { path: '/order/alipay', name: 'alipay', component: () => import('./../views/alipay.vue') }
      ]
    }
  ]
})
